#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define MAX_CARDS 16
#define MIN_PLAYERS 2
#define PLAYER_RANGE 2.9999999999 /* difference between max and min players + 1 */
#define MODULUS 2147483647

/* int _setupCardTestHelper(char *cardName, int card, long seed, int k[10], struct gameState *G){ */
/*   int initSeed, i, testCardPos; */
  
/*   /\* fill in the game state with garbage *\/ */
/*   for(i = 0; i < sizeof(struct gameState); i++){ */
/*     ((char*)G[i] = floor(Random()*256)); */
/*   } */
/*   /\* initialize new game *\/ */
/*   numPlayers = floor(Random() * 1000);  */
/*   initSeed = floor(Random() * 1000); */
/*   initializeGame(numPlayers, k, seed, G); */
/*   for(i = 0; i < numPlayers; i++){ */
/*     G->deckCount[i] = floor(Random() * MAX_DECK) + 5; // a few extra to draw from if needed */
/*     G->discardCount[i] = floor(Random() * MAX_DECK); */
/*     G->handCount[i] = floor(Random() * MAX_HAND); */
/*   } */
/*   currentPlayer = floor(Random() * numPlayers); //identify a random player */
/*   G->whoseTurn = currentPlayer; //set the current to our identified player */
/*   testCardPos = floor(Random() * G->handCount[currentPlayer]); //identify a random card in our current player's hand */
/*   G.hand[currentPlayer][testCardPos] = card; //set identified random card to card to be tested */
  
/*   return 0; */
/* } */
  

/* int setupCardTest(int card, struct gameState *G){ */

/*   return 0; */
/* } */
  
int gameStateDiff(struct gameState *state1, struct gameState *state2){
  int i, j;
  
  //check number of players
  if(state1->numPlayers != state2->numPlayers){
    printf("Mismatch Number of Players\n");
    return 0;
  }
  //check supply counts
  for(i = 0; i < treasure_map + 1; i++){
    if(state1->supplyCount[i] != state2->supplyCount[i]){
      printf("Mismatch Number of SupplyCounts at %d\n", i);
      return 0;
    }
  }
  //check embargo tokens
  for(i = 0; i < treasure_map + 1; i++){
    if(state1->embargoTokens[i] != state2->embargoTokens[i]){
      printf("Mismatch Number of embargo tokens at %d\n", i);
      return 0;
    }
  }
  //check outpost played
  if(state1->outpostPlayed != state2->outpostPlayed){
    printf("Mismatch outpost played\n");
    return 0;
  }
  //check outpost turn
  if(state1->outpostTurn != state2->outpostTurn){
    printf("Mismatch outpost turn\n");
    return 0;
  }
  //check whose turn
  if(state1->whoseTurn != state2->whoseTurn){
    printf("Mismatch whose turn. state1: %d\t state2: %d\n", state1->whoseTurn, state2->whoseTurn);
    return 0;
  }
  // check phase
  if(state1->phase != state2->phase){
    printf("Mismatch Phase\n");
    return 0;
  }
  // check number of actions
  if(state1->numActions != state2->numActions){
    printf("Mismatch Number of Actions\n");
    return 0;
  }
  // check coins
  if(state1->coins != state2->coins){
    printf("Mismatch Coins: %d vs. %d\n", state1->coins, state2->coins);
    return 0;
  }
  // check number of buys
  if(state1->numBuys != state2->numBuys){
    printf("Mismatch Number of buys\n");
    return 0;
  }
  // check hand
  for(i = 0; i < MAX_PLAYERS; i++){
    for(j = 0; j < MAX_HAND; j++){
      if(state1->hand[i][j] != state2->hand[i][j]){
	printf("Mismatch Hand at player %d, card %d\n", i, j);
	return 0;
      }
    }
  }
  //check handCount
  for(i = 0; i < MAX_PLAYERS; i++){
    if(state1->handCount[i] != state2->handCount[i]){
      printf("Mismatch hand count at player %d\n", i);
      return 0;
    }
  }
  //check deck
  for(i = 0; i < MAX_PLAYERS; i++){
    for(j = 0; j < MAX_DECK; j++){
      if(state1->deck[i][j] != state2->deck[i][j]){
	printf("Mismatch Deck at player %d, deck %d\n", i, j);
	return 0;
      }
    }
  }
  //check deckCount
  for(i = 0; i < MAX_PLAYERS; i++){
    if(state1->deckCount[i] != state2->deckCount[i]){
      printf("Mismatch deck count at player %d\n", i);
      return 0;
    }
  }
  //check discard
  for(i = 0; i < MAX_PLAYERS; i++){
    for(j = 0; j < MAX_DECK; j++){
      if(state1->discard[i][j] != state2->discard[i][j]){
	printf("Mismatch Discard at player %d, deck %d\n", i, j);
	return 0;
      }
    }
  }
  //check discardCount
  for(i = 0; i < MAX_PLAYERS; i++){
    if(state1->discardCount[i] != state2->discardCount[i]){
      printf("Mismatch discard count at player %d\n", i);
      return 0;
    }
  }
  //check playedCards
  for(i = 0; i < MAX_DECK; i++){
    if(state1->playedCards[i] != state2->playedCards[i]){
      printf("Mismatch playedCards at deck %d\n", i);
      return 0;
    }
  }
  //check played Card Count
  if(state1->playedCardCount != state2->playedCardCount){
    printf("Mismatch Number of Played Card Count\n");
    return 0;
  }

  return 0;
}
